import http from '/src/utils/request'
import { BASEURL } from '/src/utils/request'

// 发布/编辑一个文章
export function commitArticle(form) {
  return http.post('/plugins/baliServer-module-article/api/article', form)
}

// 获取文章list
export function getArticleList(current = 1, size = 5, search = '') {
  let tmp = search === 'default' ? '' : `&search=${search}`
  if (!search) {
    return http.get(`/article/page?current=${current}&size=${size}`)
  }
  return http.get(`/article/page?current=${current}&size=${size}` + tmp)
}

// 获取获取public文件仓库内所有文件
export function getPublicFiles() {
  return http.get('/plugins/baliServer-module-netdisk/api/netdisk?fileStorageId=00&fileFolderId=00')
}

// 根据文件Id下载文件
export function downloadById(fileId) {
  return http.get(`/plugins/baliServer-module-netdisk/api/netdisk/downloadById?fileId=${fileId}`)
}
// 根据文件Id下载文件
export function shareById(fileId) {
  let url = BASEURL+'/plugins/baliServer-module-netdisk/api/netdisk'
  return http.get(`/plugins/baliServer-module-netdisk/api/netdisk/getqrcode?fileId=${fileId}&url=${url}`)
}
// 获取文件详细
export function getFileDetail(fileId) {
  return http.get(`/plugins/baliServer-module-netdisk/api/netdisk/getFileByFileId?fileId=${fileId}`)
}
// 根据用户id获取用户的网盘空间
export function listByUserId(uid) {
  return http.get(`/plugins/baliServer-module-netdisk/api/netdisk/listByUserId?userId=${uid}`)
}
export function listFiles(fileStorageId,fileFolderId){
  return http.get(`/plugins/baliServer-module-netdisk/api/netdisk?fileStorageId=${fileStorageId}&fileFolderId=${fileFolderId}`)
}
// 重命名文件
export function renameFile(uploadfile) {
  return http.post('/plugins/baliServer-module-netdisk/api/netdisk/updateFileName', uploadfile)
}
// 重命名文件夹
export function renameFileFolder(fileFolderId) {
  return http.get(`/plugins/baliServer-module-netdisk/api/netdisk/listByUserId?userId=${uid}`)
}
// 删除文件与文件夹
export function deleteFile(id) {
  return http.post(`/plugins/baliServer-module-netdisk/api/netdisk/delete?id=${id}`)
}
// 新建文件夹
export function addFileFolder(fileFolder) {
  return http.post('/plugins/baliServer-module-netdisk/api/netdisk/addFileFolder',fileFolder)
}
// 获取当前fileUser、fileStorage、fileFileFolder
export function getNetdisk(uid) {
  return http.get(`/plugins/baliServer-module-netdisk/api/netdisk/getNetdisk?userId=${uid}`)
}
// 获取指定文件目录信息
export function getFileFolder(fileFolderId) {
  return http.get(`/plugins/baliServer-module-netdisk/api/netdisk/getFileFolder?fileFolderId=${fileFolderId}`)
}